var express = require('express');
var app = express();
var fs = require("fs");

var bodyParser = require('body-parser');


app.use(express.static('public'));

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
// app.use(multer({ dest: '/tmp/'}).array('image'));

//路由
var uploadfile = require('./lib/uploadfile');

//拦截器
app.all('/*', function(req, res, next){
  var url=req.originalUrl;
  if(url.indexOf('/upliu')!=-1){
    app.use('/upliu', uploadfile);
    next();
    return;
  }else{
    res.send('Hello World!')
  }
});

var server = app.listen(8081, function () {

  var host = server.address().address
  var port = server.address().port

  console.log("upload，address: http://%s:%s", host, port)

})